
cd "/Users/marianaach/Desktop/Data_Alvarado"

use weights_us.dta

destring male ethnicity educ hhinc zip partyid, replace

gen age29=1 if age<=29
replace age29=0 if age29==.
label var age29 "29 and under"

gen age3049=1 if age>29 & age<=49
replace age3049=0 if age3049==.
label var age3049 "30-49 years old"

label var ethnicity "Respondent race"
label define races 1 "White" 2 "Black" 3 "Hispanic" 4 "Asian" 5 "Other"
label values ethnicity races

gen white=1 if ethnicity==1
replace white=0 if white==.

label define education 1 "Less than HS" 2 "HS graduate" 3 "Some college" 4 "2yearCollege" 5 "4yearCollege" 6 "MA" 7 "PhD" 8 "Professional"
label values educ education
label var educ "Respondent level of education"

gen educ_low=0
replace educ_low=1 if educ<4

gen educ_med=0
replace educ_med=1 if educ==4 | educ==5

label define partisanship 1 "Republican" 2 "Democrat" 3 "Independent" 4 "Other"
label values partyid partisanship
label var partyid "Respondent's party id"

gen dem=0
replace dem=1 if partyid==2

gen rep=0
replace rep=1 if partyid==1

label define incomes 13 "<10k" 14 "10k-19.999" 15 "20k-29.999" 16 "30k-39,999" 18 "40k-49.999" 19 "50k-79,999" 20 "80k-99,999" 21 "100k-124,999" 22 "125k-149,999" 23 "150k-199,999" 24 ">200k"
label values hhinc incomes
label var hhinc "Respondent's annual household income"

gen inc_1=0
replace inc_1=1 if hhinc==13

gen inc_2=0
replace inc_2=1 if hhinc==14

gen inc_3=0
replace inc_3=1 if hhinc==15

gen inc_4=0
replace inc_4=1 if hhinc==16

gen inc_5=0
replace inc_5=1 if hhinc==18

gen inc_6=0
replace inc_6=1 if hhinc==19

gen inc_7=0
replace inc_7=1 if hhinc==20

gen noeast=0
replace noeast=1 if zip>=1001 & zip<=19526

gen south=0
replace south=1 if zip>=19702 & zip<=42726
replace south=1 if zip>=70001 & zip<=79924

gen midwest=0
replace midwest=1 if zip>=43026 & zip<=58701
replace midwest=1 if zip>=60005 & zip<=68845

gen west=0
replace west=1 if zip>=59044 & zip<=59901
replace west=1 if zip>=80003 & zip<=99645

ebalance male dem rep white age29 age3049 educ_low educ_med inc_1 inc_2 inc_3 inc_4 inc_5 inc_6 inc_7 noeast midwest south, manualtargets(0.49 0.345 0.281 0.78 0.213 0.335 0.598 0.291 0.046 0.073 0.084 0.087 0.077 0.205 0.105 0.179 0.21 0.375) replace

keep responseid _webal
rename _webal webal

saveold weights_us_ready.dta, version(12) replace

clear
